package com.xjc.business.controller.sysadmin;

import com.xjc.business.entity.po.sysadmin.ReplyApplyPo;
import com.xjc.business.entity.vo.PageVo;
import com.xjc.business.entity.vo.sysadmin.SchoolApplyPageVo;
import com.xjc.business.service.SchoolApplysService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 徐锦程
 * 时间:2025-01-25 20:46
 */
@RestController("sys_school_apply_controller")
@RequestMapping("/sys_admin/{school_apply}")
public class SchoolApplyController {

    @Autowired
    SchoolApplysService schoolApplysService;

    /**
     * 分页查询学校申请
     * @param pageSize 每页条数
     * @param currentPage 当前页码
     * @param schoolName 学校名称
     * @return 学校数据
     */
    @GetMapping("/page/{pageSize}/{currentPage}")
    public Result<PageVo<SchoolApplyPageVo>> getSchoolApplyPage(@PathVariable(value = "pageSize",required = false) Integer pageSize,@PathVariable(value = "currentPage",required = false) Integer currentPage, String schoolName, Integer status) {
        if(pageSize == null || pageSize <= 0){
            pageSize = 10;
        }
        if(currentPage == null || currentPage <= 0){
            currentPage = 1;
        }
        if(schoolName == null){
            schoolName = "";
        }

        if(status == null){
            status = -1;
        }
        return schoolApplysService.getSchoolApplyPage(pageSize, currentPage, schoolName, status);
    }


    /**
     * 审核学校申请
     * @param replyApplyPo 信息
     * @return 反馈
     */
    @PostMapping("/reply")
    public Result<String> replyApply(@RequestBody(required = false) ReplyApplyPo replyApplyPo){
        if (replyApplyPo == null || replyApplyPo.getApplyId() == null || replyApplyPo.getStatus() == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return schoolApplysService.replyApply(replyApplyPo);
    }
}
